package com.vito.framework.system.dict.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vito.framework.base.service.impl.BaseServiceImpl;
import com.vito.framework.system.dict.mapper.DictManageMapper;
import com.vito.framework.system.dict.model.SysDict;
import com.vito.framework.system.dict.service.DictService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/***************************************************************
 * Name:        DictService.java     
 * Create At:   2010-07-01
 * Module:      区域管理
 * Description: [系统管理-从字典表获取下拉框值]
 * Author       zhaowentao
 * ------------------------------------------------------------
 * 修改历史
 * 序号  日期  修改人   修改原因
 * 1
 * 2
 ***************************************************************/
@Service
public class DictServiceImpl extends BaseServiceImpl<DictManageMapper, SysDict> implements DictService {

    /**
     * Author:wanghuaifu
     * Create At:2013-01-05
     * Description: [根据类型和编码获取有效的字典数据]
     * type 类型
     * status 状态
     * Condition 指定编码
     *
     * @return String
     */
    @Override
    public String getTypeList(String type, String status, String Condition) {
        String str = "";
        List<SysDict> dictList = list(new LambdaQueryWrapper<SysDict>().orderByAsc(SysDict::getSort));
        if (dictList != null && type != null && !"".equals(type.trim()) && status != null) {
            for (SysDict dict : dictList) {
                if (type.equals(dict.getPtypeCode()) && status.equals(dict.getStatus()) && Condition.equals(dict.getDictCode())) {
                    str = dict.getDictName();
                }
            }
        }
        return str;
    }

    /**
     * Author:zhaowentao
     * Create At:2010-06-22
     * Description: [根据类型获取下拉列表 有效或无效的都获取]
     *
     * @return String
     */
    @Override
    public List<SysDict> getTypeList(String type) {
        List<SysDict> list = new ArrayList<>();
        List<SysDict> dictList = list(new LambdaQueryWrapper<SysDict>().orderByAsc(SysDict::getSort));
        if (dictList != null && type != null && !"".equals(type.trim())) {
            for (SysDict dict : dictList) {
                if (type.equals(dict.getPtypeCode())) {
                    list.add(dict);
                }
            }
        }
        return list;
    }

    /**
     * Author:shanzhitong
     * Create At:2017-05-07
     * Description: [根据类型和默认值获取名称]
     *
     * @return String
     */
    @Override
    public String getTypeName(String type, String value) {
        List<SysDict> dictList = list(new LambdaQueryWrapper<SysDict>().orderByAsc(SysDict::getSort));
        if (dictList != null) {
            for (SysDict dict : dictList) {
                if (dict.getPtypeCode().equals(type) && dict.getDictCode().equals(value)) {
                    return dict.getDictName();
                }
            }
        }
        return value;
    }
}